/**
 * jims
 */
package com.jims.master.modules.blood.web;



import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jims.master.common.data.StringData;
import com.jims.master.common.web.BaseController;
import com.jims.master.common.utils.StringUtils;
import com.jims.master.modules.blood.entity.BloodCapacity;
import com.jims.master.modules.blood.service.BloodCapacityService;

import java.util.Date;
import java.util.List;

/**
 * 申请用血量表Controller
 * @author CTQ
 * @version 2017-04-10
 */
@Controller
@RequestMapping(value = "${adminPath}/blood/bloodCapacity")
public class BloodCapacityController extends BaseController {

	@Autowired
	private BloodCapacityService bloodCapacityService;
	
	@ModelAttribute
	public BloodCapacity get(@RequestParam(required=false) String id) {
		BloodCapacity entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = bloodCapacityService.get(id);
		}
		if (entity == null){
			entity = new BloodCapacity();
		}
		return entity;
	}
	
	@RequiresPermissions("user")
	@RequestMapping(value = {"list", ""})
	public String list(BloodCapacity bloodCapacity,Model model) {
		List<BloodCapacity> list = bloodCapacityService.findList(bloodCapacity);
		model.addAttribute("list", list);
		return "modules/blood/bloodCapacityList";
	}

	@RequiresPermissions("user")
	@RequestMapping(value = "form")
	public String form(BloodCapacity bloodCapacity, Model model) {
		bloodCapacity.setTransDate(new Date());
		model.addAttribute("bloodCapacity", bloodCapacity);
		return "modules/blood/bloodCapacityForm";
	}

	@RequiresPermissions("user")
	@RequestMapping(value = "save")
	@ResponseBody
	public StringData save(BloodCapacity bloodCapacity) {
	    StringData data=new StringData();
		int i=bloodCapacityService.save(bloodCapacity);
        if(i>0){
            data.setCode("success");
            data.setData("保存申请用血量表成功");
        }else{
            data.setCode("error");
            data.setData("保存申请用血量表失败");
        }
        return data;
	}
	@RequiresPermissions("user")
	@RequestMapping(value = "delete")
	@ResponseBody
	public StringData delete(BloodCapacity bloodCapacity) {
	    StringData data=new StringData();
		int i=bloodCapacityService.delete(bloodCapacity);
        if(i>0){
            data.setCode("success");
            data.setData("删除申请用血量表成功");
        }else{
            data.setCode("error");
            data.setData("删除申请用血量表失败");
        }
		return data;
	}

}